<template>
  <div id="unit" class="flex-row">
    <gas-price-list v-ref:list :row="row" @select-changed="selected" style="width:50%"></gas-price-list>
    <div style="width:50%; margin-left: 20px;" class="flex" v-if="isdetail">
      <!-- <p class="bg-info text-center" style="padding: 8px;" v-if="row.pricecount">气价变更情况汇总</p> -->
      <ul class="nav nav-tabs" v-if="row.pricecount">
        <li class="active"><a href="#">气价变更情况汇总</a></li>
      </ul>
      <div style="max-height: 200px;" v-if="row.pricecount">
        <update-info v-ref:update :data="row" :parent-data="parentData" @select-changed="selected2"></update-info>
      </div>
      <gas-price :data="row" @close="refresh" v-ref:gas></gas-price>
    </div>
  </div>
</template>
<script>
/**
*阶梯气价管理组件
*/
import LoadData from '../../../../plugins/revenueService/LoadData'
export default {
  title: '气价管理',
  data () {
    return {
      row: null,
      parentData: '',
      isdetail: false
    }
  },
  methods: {
    selected (obj) {
      this.row = obj.val
      this.parentData = this.row.id
      this.isdetail = true
      if (this.row.pricecount <= 1) {
        this.row.pricecount = null
      }
    },
    selected2 (obj) {
      this.row = Object.assign({}, this.row, obj.val)
    },
    refresh () {
      this.row = null
      this.isdetail = false
      this.$refs.list.search()
    }
  },
  events: {
    'success' (name, row, res) {
      this.row = row
      // LoadData.load()
      this.isdetail = false
      this.$refs.list.search()
      if (row.pricecount) {
        this.$refs.update.getUpdate()
      }
    },
    'error' (name, row, res) {
      this.row = row
      this.isdetail = false
      this.$refs.list.search()
      if (row.pricecount) {
        row.pricecount === 1
        this.$refs.update.getUpdate()
      }
    },
    'close' (res) {
      this.row = null
      this.isdetail = false
    },
    'search' () {
      this.row = null
      this.isdetail = false
      // this.$refs.list.search()
    },
    'add' () {
      this.isdetail = true
      this.$refs.list.$refs.paged.$refs.grid.selectStore.selected = null
      this.row = null
      // this.$refs.gas.initModel()
    }
  }
}
</script>
